@echo off
for /f "delims=: tokens=1,2*" %%i in ('type %~dp0ipconf.txt ^| findstr /n .*') do set abc%%i=%%j
set ip=%abc1%
echo %ip%


for /f "tokens=1-3 delims=-/ " %%1 in ("%date%") do set ddd=%%1%%2%%3
for /f "tokens=1-4 delims=.: " %%1 in ("%time%") do set tttt=%%1%%2%%3%%4
set DT=%ddd%%tttt%


set saveDir=%~dp0%ip%_%DT%
set saveDir=%~dp0target\%ip%


if exist %saveDir% (
   echo Error: Directory already exists
   rem del /s /q %saveDir%
   goto end
) else (
  mkdir %saveDir%
)

echo %saveDir%

keytool -validity 36500 -genkey -v -alias server -keyalg RSA -keystore %saveDir%\server.keystore -dname "CN=%ip%,OU=sss,O=sss,L=BeiJing,ST=BeiJing,c=cn" -storepass 123456 -keypass 123456 -ext san=ip:%ip%

keytool -export -v -alias server -keystore %saveDir%\server.keystore -storepass 123456 -rfc -file %saveDir%\server.cer

:end
pause
